package com.example.vertification.service;

import com.example.vertification.Utils.RedisUtil;
import com.example.vertification.entity.ChatMessage;
import com.example.vertification.entity.User;
import com.example.vertification.repository.ChatRepository;
import com.example.vertification.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class ChatMessageService {

    @Autowired
    private RedisUtil redisUtil;

    private final ChatRepository chatMessageRepository;

    @Autowired
    public ChatMessageService(ChatRepository chatMessageRepository) {
        this.chatMessageRepository = chatMessageRepository;
    }

    public ChatMessage createChatMessage(ChatMessage e) {
        return chatMessageRepository.save(e);
    }

    public ChatMessage SaveMessage(ChatMessage e) {
        return chatMessageRepository.save(e);
    }


    public List<ChatMessage> getContent(String s,String r) {

        return chatMessageRepository.findBySenderUidAndReceiverUid(Long.parseLong(s),Long.parseLong(r));
    }


    public List<ChatMessage> findBySenderUid(String s) {
        return chatMessageRepository.findBySenderUid(Long.parseLong(s));
    }

    public List<ChatMessage> findByReceiverUid(String s) {
        return chatMessageRepository.findByReceiverUid(Long.parseLong(s));
    }

}